package com.example.exp06_contentprovider_contacts;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private Button callButton,queryButton;
    private EditText editText;
    private TextView textView;
    ContentValues values = new ContentValues();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        callButton = findViewById(R.id.CallButton);
        queryButton = findViewById(R.id.QueryButton);
        editText = findViewById(R.id.editTextPhoneNumber);
        textView = findViewById(R.id.textView_contactName);

        // 使用ContentResolver来获取ContentProvider
        ContentResolver resolver = getContentResolver();

        // 先添加一个联系人（使得存在查询能够成功的例子）
        values.clear();
        values.put(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, "骆锟宏");
        values.put(ContactsContract.CommonDataKinds.Phone.NUMBER, "18016661622");
        Uri uri = resolver.insert(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, values);

        // 查询&拨号
        queryButton.setOnClickListener(this);
        callButton.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        switch(view.getId()){
            case R.id.QueryButton:


                break;
            case R.id.CallButton:

                break;
        }
    }
}